#ifndef COMPOSITEVALIDATOR_H
#define COMPOSITEVALIDATOR_H

#include "stringvalidator.h"

class CompositeValidator : public StringValidator
{
public:
    CompositeValidator();
    enum LogicType { AND, OR };

    CompositeValidator(LogicType type, const QString& errorMsg = "Composite validation failed")
        : m_type(type), m_errorMsg(errorMsg) {}

    void addValidator(ValidatorPtr validator) {
        m_validators.push_back(validator);
    }

    ValidationResult validate(const QString& input,
                              const std::vector<ValidationOption>& options = {}) const override {
        if (m_validators.empty()) {
            return ValidationResult(true);
        }

        QStringList errors;
        bool anyValid = false;
        bool allValid = true;

        for (const auto& validator : m_validators) {
            ValidationResult result = validator->validate(input, options);
            if (!result.isValid) {
                allValid = false;
                errors << result.errorMessage;
            } else {
                anyValid = true;
            }
        }

        if ((m_type == AND && allValid) || (m_type == OR && anyValid)) {
            return ValidationResult(true);
        }

        return ValidationResult(false, m_errorMsg + ":\n- " + errors.join("\n- "));
    }

private:
    LogicType m_type;
    std::vector<ValidatorPtr> m_validators;
    QString m_errorMsg;
};

#endif // COMPOSITEVALIDATOR_H
